﻿using Infrastructure.Extend;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Domain.Model.ValueObject
{
    ///<summary>
    /// EasyUI控件可传参数
    /// </summary>
    [Serializable]
    public class EasyUiParams
    {

        /// <summary>
        /// 排序的方式:升序或者降序
        /// </summary>
        public string Order { get; set; }

        /// <summary>
        /// 是否是升序排序
        /// </summary>
        public bool IsAscending
        {
            get
            {
                if (this.Order != null)
                {
                    return !this.Order.ToLower().Trim().Equals("desc");
                }
                return true;
            }
        }

        /// <summary>
        /// 排序的字段
        /// </summary>
        public string Sort { get; set; }

        /// <summary>
        /// 当前的页码
        /// </summary>
        public int Page { get; set; }

        /// <summary>
        /// 每页的记录条数
        /// </summary>
        public int Rows { get; set; }

        /// <summary>
        /// 获取搜索关键字安全类型
        /// </summary>
        public string SafeKeyword
        {
            get
            {
                return Regex.Replace(this.Keyword.NullThenEmpty(), @"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']", string.Empty);
            }
        }

        /// <summary>
        /// 搜索关键字
        /// </summary>
        public string Keyword { get; set; }

        /// <summary>
        /// 系统id
        /// </summary>
        public int SystemID { get; set; }

        /// <summary>
        /// 转换为OrderByString
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("{0} {1}", this.Sort, this.Order);
        }
    }
}
